﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Model;
using Service;


namespace ItaServicos.Controllers
{
    public class PessoaController : Controller
    {
        private GerenciadorPessoa gPessoa;

        public PessoaController()
        {
            gPessoa = new GerenciadorPessoa();
        }


        //
        // GET: /Pessoa/

        public ActionResult Index()
        {

            ViewBag.Message = "ITASERVICOS";
            return View();
        }

        //
        // GET: /Pessoa/Details/5
        [HttpGet]
        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Pessoa/Create
        [HttpGet]
        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Pessoa/Create

        [HttpPost]
        public ActionResult Create(PessoaModel pessoa)
        {

            try
            {
                if (!ModelState.IsValid)
                {
                    gPessoa.Inserir(pessoa);
                    return RedirectToAction("Index");

                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Pessoa/Edit/5
        [HttpGet]
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Pessoa/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Pessoa/Delete/5

        [HttpGet]
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Pessoa/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
